package com.wuliu.driver.service;

import com.wuliu.driver.mapper.CarMapper;
import com.wuliu.driver.pojo.Car;
import com.wuliu.driver.pojo.Orders;
import com.wuliu.driver.util.Code;
import com.wuliu.driver.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarServiceImpl implements CarService{
    @Autowired
    private CarMapper carMapper;
    @Override
    public Result ins(Car Car) {
        Integer select = carMapper.select(Car.getDid());
        if (select != null){
            int i = carMapper.updStatus(Car.getDid());
            if (i>0){
                return new Result(Code.GET_OK,"修改成功");
            }
            return new Result(Code.GET_ERR,"修改失败");
        }else {
            int insert = carMapper.insert(Car);
            if (insert>0){
                return new Result(Code.GET_OK,"添加成功");
            }
            return new Result(Code.GET_ERR,"添加失败");
        }

    }

    @Override
    public List<Car> che(Integer id) {
        List<Car> che = carMapper.che(id);
        return che;
    }


    @Override
    public Result cha(Integer did) {
        List<Car> cha = carMapper.cha(did);
        if (cha.size()>0){
            return new Result(Code.GET_OK,cha,"查询成功");
        }
        return new Result(Code.GET_ERR,"查询失败");
    }

    @Override
    public List<Orders> yun(Integer id) {
        List<Orders> yun = carMapper.yun(id);
        return yun;
    }
}
